Inside Macintosh: QuickTime

Previous | Chapter Top | Chapter Contents | Next

Working With Movie User Data

Each movie, track, and media can contain a user data list, which your application can use in any way you want. A user data list contains all the user data for a movie, track, or media. Each user data list may contain one or more user data items. All QuickTime user data items share several attributes.

First, each user data item carries a type identifier. This type is similar to a Resource Manager resource type, and is stored in a long integer. Apple has reserved all lowercase user data type values. You are free to create user data type values using uppercase letters. Apple recommends using type values that begin with the © character (Option-G) to specify user data items that store text data.

The following user data types are currently defined:

'© nam'

Movie's name

'© cpy'

Copyright statement

'© day'

Date the movie content was created

'© dir'

Name of movie's director

ed1' to ed9'

Edit dates and descriptions

'© fmt'

Indication of movie format (computer-generated, digitized, and so on)

'© inf'

Information about the movie

'© prd'

Name of movie's producer

'© prf'

Names of performers

'© req'

Special hardware and software requirements

'© src'

Credits for those who provided movie source content

'© wrt'

Name of movie's writer

User data items of these types must contain text data only.

Second, the Movie Toolbox allows you to create more than one user data item in a user data list. Therefore, each user data item is identified by a unique index. Index values are assigned sequentially within a user data type and start at 1.

Finally, you may create alternate text for a given user data text item. For example, you may want to support multiple languages and may therefore want to create different text for each language. The Movie Toolbox allows you to specify different versions of the text of a single user data item. These versions are distinguished by their region code values.

The Movie Toolbox provides a number of functions that allow you to work with user data. Before you can work with the contents of a user data list, you must obtain a reference to the list. The GetMovieUserData , GetTrackUserData , or GetMediaUserData functions allow you to get a reference to a user data list. You can then use the GetUserData , AddUserData , and RemoveUserData functions to work with the items contained in the user data list. If your user data items contain text data, you can use the AddUserDataText , GetUserDataText , and RemoveUserDataText functions to work with the text of a user data item. Note that a single user data item can store either text or other data, but not both.

You can count the number of user data items of a specified type in a movie, track, or media by calling the CountUserDataType function. You can use the GetNextUserDataType function to scan all the types of user data in a specified user data list.

The Movie Toolbox also supplies a number of functions for the manipulation of user data. The SetUserDataItem and GetUserDataItem functions allow easy access to data stored in user data items. The NewUserData and DisposeUserData functions provide for the use of user data outside of the immediate context of QuickTime movies. Your applications and components can also create user data structures. The PutUserDataIntoHandle and the NewUserDataFromHandle functions permit user data to be stored and retrieved in a manner similar to public movies (also called atoms ). See the chapter "Movie Resource Formats" in this book for details on atoms.

GetMovieUserData

The GetMovieUserData function allows your application to obtain access to a movie's user data list. You can then use the GetUserData , AddUserData , and RemoveUserData functions (described on GetUserData , AddUserData , and RemoveUserData , respectively) to manipulate the contents of the user data list. If the data list contains text data, you can use the GetUserDataText , AddUserDataText , and RemoveUserDataText functions (described on GetUserDataText , AddUserDataText , and RemoveUserDataText , respectively) to work with its contents.

pascal UserData GetMovieUserData (Movie theMovie);
theMovie
Specifies the movie for this operation. Your application obtains this movie identifier from such functions as NewMovie , NewMovieFromFile , and NewMovieFromHandle (described on NewMovie , NewMovieFromFile , and NewMovieFromHandle , respectively).

DESCRIPTION

The GetMovieUserData function returns a reference to the movie's user data list. This reference is valid until you dispose of the movie. When you save the movie, the Movie Toolbox saves the user data as well. If the function could not locate the movie's user data, it sets this returned value to nil .

ERROR CODES

invalidMovie

-2010

This movie is corrupted or invalid

Memory Manager errors

SEE ALSO

You can use the GetMediaUserData function (described on GetMediaUserData ) to gain access to a media's user data. Similarly, you can use the GetTrackUserData function (described in the next section) to work with a track's user data.

GetTrackUserData

The GetTrackUserData function allows your application to obtain access to a track's user data list. You can then use the GetUserData , AddUserData , and RemoveUserData functions (described on GetUserData , AddUserData , and RemoveUserData , respectively) to manipulate the contents of the user data list. If the data list contains text data, you can use the GetUserDataText , AddUserDataText , and RemoveUserDataText functions (described on GetUserDataText , AddUserDataText , and RemoveUserDataText , respectively) to work with its contents.

pascal UserData GetTrackUserData (Track theTrack);
theTrack
Specifies the track for this operation. Your application obtains this track identifier from such Movie Toolbox functions as NewMovieTrack and GetMovieTrack (described on NewMovieTrack and GetMovieTrack , respectively).

DESCRIPTION

The GetTrackUserData function returns a reference to the track's user data list. This reference is valid until you dispose of the track. When you save the track, the Movie Toolbox saves the user data as well. If the function could not locate the track's user data, it sets this returned value to nil .

ERROR CODES

invalidTrack

-2009

This track is corrupted or invalid

Memory Manager errors

SEE ALSO

You can use the GetMediaUserData function to gain access to a media's user data (described on GetMediaUserData ). Similarly, you can use the GetMovieUserData function (described on GetMovieUserData ) to work with a movie's user data.

GetMediaUserData

The GetMediaUserData function allows your application to obtain access to a media's user data list. You can then use the GetUserData , AddUserData , and RemoveUserData functions (described on GetUserData , AddUserData , and RemoveUserData , respectively) to manipulate the contents of the user data list. If the data list contains text data, you can use the GetUserDataText , AddUserDataText , and RemoveUserDataText functions (described on GetUserDataText , AddUserDataText , and RemoveUserDataText , respectively) to work with its contents.

pascal UserData GetMediaUserData (Media theMedia);
theMedia
Specifies the media for this operation. Your application obtains this media identifier from such Movie Toolbox functions as NewTrackMedia and GetTrackMedia (described on NewTrackMedia and GetTrackMedia , respectively).

DESCRIPTION

The GetMediaUserData function returns a reference to the media's user data list. This reference is valid until you dispose of the media. When you save the media, the Movie Toolbox saves the user data as well. If the function could not locate the media's user data, it sets this returned value to nil .

ERROR CODES

invalidMedia

-2008

This media is corrupted or invalid

Memory Manager errors

SEE ALSO

You can use the GetMovieUserData function to gain access to a movie's user data (described on GetMovieUserData ). Similarly, you can use the GetTrackUserData function (described in the previous section) to work with a track's user data.

GetNextUserDataType

The GetNextUserDataType function allows you to retrieve the next user data type in a specified user data list. You can use this function to scan all the user data types in a user data list.

pascal long GetNextUserDataType (UserData theUserData,
                                         OSType udType);
theUserData
Specifies the user data list for this operation. You obtain this list reference by calling the GetMovieUserData , GetTrackUserData , or GetMediaUserData function (described on GetMovieUserData , GetTrackUserData , and GetMediaUserData , respectively).
udType
Specifies a user data type. Set this parameter to 0 to retrieve the first user data type in the user data list. On subsequent requests, use the previous value returned by this function.

DESCRIPTION

The GetNextUserDataType function returns an operating-system data type containing the next user data type value in the specified user data list. When you reach the end of the user data list, this function sets the returned value to 0. You can use this value to stop your scanning loop.

ERROR CODES

None

CountUserDataType

The CountUserDataType function allows you to determine the number of items of a given type in a user data list.

pascal short CountUserDataType (UserData theUserData,
                                         OSType udType);
theUserData
Specifies the user data list for this operation. You obtain this list reference by calling the GetMovieUserData , GetTrackUserData , or GetMediaUserData function (described on GetMovieUserData , GetTrackUserData , and GetMediaUserData , respectively).
udType
Specifies the type. The Movie Toolbox determines the number of items of this type in the user data list.

DESCRIPTION

The CountUserDataType function returns a short integer that contains the number of items of the specified type in the user data list.

ERROR CODES

None

AddUserData

The AddUserData function allows your application to add an item to a user data list. You specify the user data list, the data to be added, and the data's type value.

pascal OSErr AddUserData (UserData theUserData,
                                         Handle data, OSType udType);
theUserData
Specifies the user data list for this operation. You obtain this item reference by calling the GetMovieUserData , GetTrackUserData , or GetMediaUserData function (described on GetMovieUserData , GetTrackUserData , and GetMediaUserData , respectively).
data
Contains a handle to the data to be added to the user data list.
udType
Specifies the type that is to be assigned to the new item.

DESCRIPTION

The Movie Toolbox places the specified data into the user data and assigns an index value that identifies the new item.

ERROR CODES

Memory Manager errors

GetUserData

The GetUserData function returns a specified user data item.

pascal OSErr GetUserData (UserData theUserData, Handle data,
                                         OSType udType, long index);
theUserData
Specifies the user data list for this operation. You obtain this list reference by calling the GetMovieUserData , GetTrackUserData , or GetMediaUserData function (described on GetMovieUserData , GetTrackUserData , and GetMediaUserData , respectively).
data
Contains a handle that is to receive the data from the specified item. The GetUserData function resizes this handle as appropriate to accommodate the item. Your application is responsible for releasing this handle when you are done with it. Set this parameter to nil if you do not want to retrieve the user data item. This can be useful if you want to verify that a user data item exists, but you do not need to work with the item's contents.
udType
Specifies the item's type value.
index
Specifies the item's index value. This parameter must specify an item in the user data list identified by the parameter theUserData .

ERROR CODES

userDataItemNotFound

-2026

Cannot locate this user data item

Memory Manager errors

RemoveUserData

The RemoveUserData function removes an item from a user data list. After the Movie Toolbox removes the item, it renumbers the remaining items of that type so that the index values are sequential and start at 1.

pascal OSErr RemoveUserData (UserData theUserData, OSType udType,
                                         long index);
theUserData
Specifies the user data list for this operation. You obtain this list reference by calling the GetMovieUserData , GetTrackUserData , or GetMediaUserData function (described on GetMovieUserData , GetTrackUserData , and GetMediaUserData , respectively).
udType
Specifies the item's type value.
index
Specifies the item's index value. This parameter must specify an item in the user data list identified by the parameter theUserData .

ERROR CODES

userDataItemNotFound

-2026

Cannot locate this user data item

Memory Manager errors

AddUserDataText

The AddUserDataText function allows your application to place language-tagged text into an item in a user data list. You specify the user data list and item, the data to be added, the data's type value, and the language code of the data.

pascal OSErr AddUserDataText (UserData theUserData, Handle data,
                                         OSType udType, long index,
                                         short itlRegionTag);
theUserData
Specifies the user data list for this operation. You obtain this list reference by calling the GetMovieUserData , GetTrackUserData , or GetMediaUserData function (described on GetMovieUserData , GetTrackUserData , and GetMediaUserData , respectively).
data
Contains a handle to the data to be added to the user data list.
udType
Specifies the type that is to be assigned to the new item.
index
Specifies the item to which the text is to be added. This parameter must specify an item in the user data list identified by the parameter theUserData .
itlRegionTag
Specifies the region code of the text to be added. If there is already text with this region code in the item, the function replaces the existing text with the data specified by the data parameter. See Inside Macintosh: Text for more information about language and region codes.

DESCRIPTION

The Movie Toolbox places the specified data into the user data item. If the item does not exist when you call this function, the Movie Toolbox creates a new item for you (this is true only if the item you are adding is the first item in the list; otherwise, you must create the item yourself).

ERROR CODES

userDataItemNotFound

-2026

Cannot locate this user data item

Memory Manager errors

GetUserDataText

The GetUserDataText function allows your application to retrieve language-tagged text from an item in a user data list. You specify the user data list and item, and the item's type value and language code. The Movie Toolbox retrieves the specified text from the user data item.

pascal OSErr GetUserDataText (UserData theUserData, Handle data,
                                         OSType udType, long index,
                                         short itlRegionTag);
theUserData
Specifies the user data list for this operation. You obtain this list reference by calling the GetMovieUserData , GetTrackUserData , or GetMediaUserData function (described on GetMovieUserData , GetTrackUserData , and GetMediaUserData , respectively).
data
Contains a handle that is to receive the data. The GetUserDataText function resizes this handle as appropriate. Your application must dispose of the handle when you are done with it.
udType
Specifies the item's type value.
index
Specifies the item's index value. This parameter must specify an item in the user data list identified by the parameter theUserData .
itlRegionTag
Specifies the language code of the text to be retrieved. See Inside Macintosh: Text for more information about language and region codes.

ERROR CODES

userDataItemNotFound

-2026

Cannot locate this user data item

Memory Manager errors

RemoveUserDataText

The RemoveUserDataText function allows your application to remove language-tagged text from an item in a user data list. You specify the user data list and item, and the item's type value and language code. The Movie Toolbox removes the specified text from the user data item.

pascal OSErr RemoveUserDataText (UserData theUserData,
                                         OSType udType, long index,
                                         short itlRegionTag);
theUserData
Specifies the user data list for this operation. You obtain this list reference by calling the GetMovieUserData , GetTrackUserData , or GetMediaUserData function (described on GetMovieUserData , GetTrackUserData , and GetMediaUserData , respectively).
udType
Specifies the item's type value.
index
Specifies the item's index value. This parameter must specify an item in the user data list identified by the parameter theUserData .
itlRegionTag
Specifies the language code of the text to be removed. See Inside Macintosh: Text for more information about language and region codes.

ERROR CODES

userDataItemNotFound

-2026

Cannot locate this user data item

Memory Manager errors

SetUserDataItem

The SetUserDataItem allows your application to set an item in a user data list. You specify the user data list, the data to be set, the size of the data to be set, and the data's type value.

pascal OSErr SetUserDataItem (UserData theUserData,
                                         void *data, long size,
                                         OSType udType, long index);
theUserData
Specifies the user data list for this operation. You obtain this item reference by calling the GetMovieUserData , GetTrackUserData , or GetMediaUserData function (described on GetMovieUserData , GetTrackUserData , and GetMediaUserData , respectively).
data
Contains a pointer to the data item to be set in a user data list.
size
Specifies the size of the information pointed to by the data parameter.
udType
Specifies the type value assigned to the new item.
index
Specifies the item's index value. This parameter must specify an item in the user data list identified by the parameter theUserData . An index value of 0 or 1 implies the first item, which is created if it doesn't already exist.

DESCRIPTION

You must provide the size of the information specified in the data parameter because the data may be embedded inside a larger data structure or may be on the stack.

SPECIAL CONSIDERATIONS

The data pointer must be locked, since SetUserDataItem may move memory.

SEE ALSO

The SetUserDataItem function is a pointer-based version of AddUserData , which is described on AddUserData .

ERROR CODES

Memory Manager errors

GetUserDataItem

The GetUserDataItem function returns a specified user data item. GetUserDataItem is a pointer-based version of the GetUserData function, which is described on GetUserData .

pascal OSErr GetUserDataItem (UserData theUserData,
                                         void *data, long size,
                                         OSType udType, long index);
theUserData
Specifies the user data list for this operation. You obtain this list reference by calling the GetMovieUserData , GetTrackUserData , or GetMediaUserData function (described on GetMovieUserData , GetTrackUserData , and GetMediaUserData , respectively).
data
Contains a pointer that is to receive the data from the specified item.
size
Specifies the size of the item.
udType
Specifies the item's type value.
index
Specifies the item's index value. This parameter must specify an item in the user data list identified by the parameter theUserData .

DESCRIPTION

If the size field provided doesn't match the exact size of the actual user data item, an error is returned. In this case, you should use GetUserData instead. GetUserDataItem is useful for retrieving small, fixed-size pieces of user data without having to create a handle. You can pass 0 or 1 for the index parameter to indicate the first item.

ERROR CODES

userDataItemNotFound

-2026

Cannot locate this user data item

Memory Manager errors

NewUserData

The NewUserData function creates a new user data structure.

pascal OSErr NewUserData (UserData *theUserData);
theUserData
Contains a pointer to the user data structure.

DESCRIPTION

You can manipulate the user data structure with any of the standard user data functions described in "Working With Movie User Data," . If the NewUserData function fails, the parameter theUserData is set to nil .

ERROR CODES

memFullErr

-108

Not enough room in heap zone

DisposeUserData

The DisposeUserData function disposes of a user data structure created by the NewUserData function.

pascal OSErr DisposeUserData (UserData theUserData);
theUserData
Specifies the user data structure that is to be disposed of. It is acceptable but unnecessary to pass nil in the parameter theUserData .

DESCRIPTION

You should call DisposeUserData only on a user data structure that you have allocated.

SPECIAL CONSIDERATIONS

Don't dispose of user data references obtained from the Movie Toolbox function GetMovieUserData , GetTrackUserData , or GetMediaUserData (described on GetMovieUserData , GetTrackUserData , and GetMediaUserData , respectively).

PutUserDataIntoHandle

The PutUserDataIntoHandle function takes a specified user data structure and replaces the contents of the handle with a publicly parseable form of the user data.

pascal OSErr PutUserDataIntoHandle (UserData theUserData,
                                         Handle h);
theUserData
Specifies the user data structure that is to be disposed of.
h
Contains a handler to the user data structure specified in the parameter theUserData .

DESCRIPTION

The contents of the h parameter are appropriate for storage as an atom, much like a public movie. See the chapter "Movie Resource Formats" in this book for details on the QuickTime atoms.

NewUserDataFromHandle

The NewUserDataFromHandle function creates a new user data structure from a handle.

pascal OSErr NewUserDataFromHandle (Handle h,
                                         UserData *theUserData);
h
Contains a handle to the data structure specified in the parameter theUserData .
theUserData
Contains a pointer to a new user data structure.

DESCRIPTION

The handle specified in the h parameter must be in the standard user data storage format (that is, as an atom, just like a public movie). Usually the handle will have been created by calling PutUserDataIntoHandle (described in the previous section).

ERROR CODES

memFullErr

-108

Not enough room in heap zone


© 1997 Apple Computer, Inc.

Previous | Chapter Top | Chapter Contents | Next